<#include "/admin/public.html">
<style type="text/css">
.layui-form-checkbox[lay-skin=primary] {
   height: 30px !important;
   line-height: 28px!important;
}
#uploadfile .filename{
	display:inline-block;
	width:180px;
}
</style>
<div class="uk-layui-form">
	<#if title?? && title == "链接设置">
			<form class="layui-form uk-form" action="/admin/configuration/saveLink.html" method="post">
			
				<input type="hidden" name="id" id="id" value="${linksetData.id!''}">
				<input type="hidden" name="title" id="title" value="${linksetData.title!''}">
			    <!-- 链接设置 -->
			    <#if title?? && title == "链接设置">
				    <div class="link-setting">
			    		<div class="layui-form-item">
				            <label class="layui-form-label">选择链接分类</label>
				            <div class="layui-input-inline">
						      	<select id="prentid" name="prentid" placeholder="请选择链接分类" lay-filter="selectPrentid">
									<#if dictList?? && dictList??>
										<#list dictList as dic>
											<option value="${dic.id!''}" <#if linksetData.prentid == dic.id>selected</#if>>${dic.label!''}</option>
										</#list>
									</#if>
								</select>
						    </div>
				        </div>
				        <div class="layui-form-item">
				            <label class="layui-form-label">链接名称</label>
				            <div class="layui-input-inline linkname">
						      	<input type="text" name="linkname"  class="layui-input" placeholder="请输入链接名称"  value="${linksetData.linkname!''}">
						      	
						    </div>
				        </div>
				        <div class="layui-form-item">
				            <label class="layui-form-label">链接地址</label>
				            <div class="layui-input-inline linkurl">
						      	<input type="text" name="linkurl"  class="layui-input" placeholder="请输入链接地址"   value="${linksetData.linkurl!''}">
						    </div>
				        </div>
			    	</div>
			    </#if>
		        <div class="layui-form-button">
		            <div class="layui-button-block">
		                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
		                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
		            </div>
		        </div>
		    </form>
		<#else>
			<form class="layui-form uk-form" action="/admin/configuration/update.html">
		    	<input type="hidden" name="id" id="id" value="${configurationmanagementData.id!''}">
		    	<input type="hidden" name="title" id="title" value="${configurationmanagementData.title!''}">
				<input type="hidden" name="imagefile" id="imagefile" value="${configurationmanagementData.imagefile!''}">
		        <input type="hidden" name="imageurl" id="imageurl"  value="${configurationmanagementData.imageurl!''}">
		        
		    	<!-- 水印设置 -->
		    	<#if configurationmanagementData?? && configurationmanagementData.title == "水印">
			    	<div class="watermaker">
			    		<div class="layui-form-item">
				            <label class="layui-form-label">当前水印</label>
				            <div class="layui-input-inline">
						      	<a class="layui-btn layui-btn-primary" id="watermakerBtn"><i class="layui-icon">&#xe608;</i>上传</a>
						    </div>
				        </div>
				        <div class="layui-form-item  <#if configurationmanagementData.imageurl == "">layui-hide</#if>">
						    <label class="layui-form-label"></label>
						    <div class="layui-input-inline">
						    	<img id="watermakerImg" style="width:130px" <#if configurationmanagementData.imageurl != "">src="/res/configurationFile/${configurationmanagementData.imageurl!''}.html"</#if><#if configurationmanagementData.imageurl == "">src=""</#if>>
						    </div>
					    </div>
			    	</div>
			    </#if>
			    
			    <!-- 公众号设置 -->
			    <#if configurationmanagementData?? && configurationmanagementData.title == "公众号">
				    <div class="vipcn">
			    		<div class="layui-form-item">
				            <label class="layui-form-label">当前二维码</label>
				            <div class="layui-input-inline">
						      	<a class="layui-btn layui-btn-primary" id="vipcnBtn"><i class="layui-icon">&#xe608;</i>上传</a>
						    </div>
				        </div>
				        <div class="layui-form-item <#if configurationmanagementData.imageurl == "">layui-hide</#if>">
						    <label class="layui-form-label"></label>
						    <div class="layui-input-inline">
						    	<img id="vipcnImg" style="width:130px" <#if configurationmanagementData.imageurl != "">src="/res/configurationFile/${configurationmanagementData.imageurl!''}.html"</#if><#if configurationmanagementData.imageurl == "">src=""</#if>>
						    </div>
					    </div>
			    	</div>
			    </#if>
			    
			    <!-- 提现设置 -->
			    <#if configurationmanagementData?? && configurationmanagementData.title == "提现设置">
				    <div class="withdrawal-set">
			    		<div class="layui-form-item">
				            <label class="layui-form-label">提现金额</label>
				            <div class="layui-input-inline">
				                <input type="text" name="amount"  lay-verify="required" id="amount" class="layui-input" placeholder="请输入提现金额" value="${configurationmanagementData.amount!?string('0.00')}">
				            </div>
				        </div>
				        <div class="layui-form-item">
				            <label class="layui-form-label">提现百分比</label>
				            <div class="layui-input-inline">
				                <input type="text" name="percentage"  lay-verify="required|percentage" id="percentage" class="layui-input" placeholder="请输入提现百分比" value="${configurationmanagementData.percentage!''}">
				            </div>
				        </div>
				        <div class="layui-form-item">
				            <label class="layui-form-label">提现说明</label>
				            <div class="layui-input-block">
				                <textarea id="explaincontent" name="explaincontent" lay-verify="required"  placeholder="请输入正文" style="width:100%;height: 260px;">${configurationmanagementData.explaincontent!''}</textarea>
				            </div>
				        </div>
			    	</div>
			    </#if>
		        <div class="layui-form-button">
		            <div class="layui-button-block">
		                <button class="layui-btn" lay-submit="*" lay-filter="formDemo">立即提交</button>
		                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
		            </div>
		        </div>
		    </form>
	</#if>
    
</div>
<script>

//触发的id
var ids = new Array("watermakerBtn","vipcnBtn");
var url = "/uploadUrlconfiguration";

layui.use(['form','laydate','layedit'], function() {
    var form = layui.form();
    //根据选择显示
    form.on('select(selectPrentid)', function(data){
    	getLinkData();
    	form.render('select');
     }); 
    
    form.verify({ 
    	percentage: function(value, item){
	  		if(!/^(100|[1-9]?\d(\.\d\d?\d?)?)%$|0$/.test(value)){
	  			return '请输入正确的百分比';
	  		}
	  	
	  	}
 	});
    
    form.on('submit(*)', function(data){});
    
    form.render(); //更新全部
});

var ue = UE.getEditor('explaincontent', {
	//这里可以选择自己需要的工具按钮名称
	toolbars: [
		['Source', 'italic', 'underline', 'Bold', 'test','forecolor','|', 'justifyleft', 'justifycenter', 'justifyright','|','insertorderedlist' ,'|',
 			'fontfamily', 'fontsize','|'
		]
	],
	wordCount: false,					//开启字数统计
	elementPathEnabled : false
});



$.each(ids,function(i,n){
	var self = this.toString();
	//实例化一个plupload上传对象
    var uploader = new plupload.Uploader({
    	browse_button:self, //触发文件选择对话框的按钮，为那个元素id
        url: "${base}" + url, //服务器端的上传页面地址
        flash_swf_url: '${ctxStatic}/plupload/js//Moxie.swf', //swf文件，当需要使用swf方式进行上传时需要配置该参数
        silverlight_xap_url: '${ctxStatic}/plupload/js/Moxie.xap', //silverlight文件，当需要使用silverlight方式进行上传时需要配置该参数
        filters: {
            mime_types: [{
                    title: "Image files",
                    extensions: "jpg,jpeg,png,gif"
                },
            ],
            max_file_size: '40mb',
        },
    });
    //在实例对象上调用init()方法进行初始化
    uploader.init();
  	//绑定各种事件，并在事件监听函数中做你想做的事
    uploader.bind('FilesAdded',function(uploader,files){
		if(uploader.settings.browse_button[0].id == "watermakerBtn"){
			$("#watermakerImg").parent().parent().removeClass("layui-hide");
			$("#watermakerImg").attr("src","/images/loading-slide.gif");
    	}else if(uploader.settings.browse_button[0].id == "vipcnBtn"){
    		$("#vipcnImg").parent().parent().removeClass("layui-hide");
			$("#vipcnImg").attr("src","/images/loading-slide.gif");
    	}
        uploader.start()
    });
  	//上传后回调
    uploader.bind('FileUploaded', function(uploader, UploadProgress, responseObject) {
        var obj = $.parseJSON(responseObject.response);
		if(uploader.settings.browse_button[0].id == "watermakerBtn"){
			$("#watermakerImg").attr("src","/res/configurationFile/" + obj.fileId +".html");
			$("#imageurl").val(obj.fileId);
			$("#imagefile").val(obj.fileName.split(".")[0]);
    	}else if(uploader.settings.browse_button[0].id == "vipcnBtn"){
    		$("#vipcnImg").attr("src","/res/configurationFile/" + obj.fileId +".html");
    		$("#imageurl").val(obj.fileId);
			$("#imagefile").val(obj.fileName.split(".")[0]);
    	}
    });
  	//报错
    uploader.bind('Error', function(up, err) {
        if (err.code == '-600') {
        	layer.msg('文件最多可上传40M', {icon: 5});
        }
    });
  	
});

if($("#title").val() == "链接设置"){
	getLinkData();
}
function getLinkData(){
	var id=$("#prentid").val();
	$.ajax({
		type: "POST",
		url: "/admin/configuration/querybyPrentid.html" ,
		dataType: "text",
		data: {prentid:id},
		async: false,
		success: function(data) {
			var jsonData = JSON.parse(data);
			
			$("#linkname").val(jsonData.linkname);
			$("#linkurl").val(jsonData.linkurl);
			/*if(jsonData.length != 0){
				$(".linkname").empty();
				$(".linkurl").empty();
				
				$(".linkname").append("<select id='linkname' name='linkname' placeholder='请选择链接名称'></select>");
				$(".linkurl").append("<select id='linkurl' name='linkurl' placeholder='请选择链接地址'></select>");
			}else{
				$(".linkname").empty();
				$(".linkurl").empty();
				$(".linkname").append("<input type='text' name='linkname'  class='layui-input' placeholder='请输入链接名称'>");
				$(".linkurl").append("<input type='text' name='linkurl'  class='layui-input' placeholder='请输入链接地址'>");
			}
			var nameOption = '',urlOpting = '';
			$.each(jsonData,function(index,item){
				nameOption = '<option value="'+item.linkname+'">'+item.linkname+'</option>';
				urlOpting = '<option value="'+item.linkurl+'">'+item.linkurl+'</option>';
				$("#linkname").append(nameOption);
				$("#linkurl").append(urlOpting);
			})*/
			
		}
		
	});
}


</script>